package com.zkthink.ceres.finance.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zkthink.base.R;
import com.zkthink.base.controller.SuperController;
import com.zkthink.base.request.PageParams;
import com.zkthink.ceres.finance.dto.*;
import com.zkthink.ceres.finance.entity.CashOutDetail;
import com.zkthink.ceres.finance.service.CashOutDetailService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.zkthink.ceres.finance.vo.CashOutDetailVO;
import com.zkthink.log.annotation.SysLog;
import com.zkthink.security.annotation.PreAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 前端控制器
 * 提现明细表
 * </p>
 *
 * @author vivi.huang
 * @date 2020-05-25
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/cashOutDetail")
@Api(value = "CashOutDetail", tags = "提现明细表")
//@PreAuth(replace = "cashOutDetail:")
@AllArgsConstructor
public class CashOutDetailController {

    private CashOutDetailService cashOutDetailService;


    /**
     * 提现
     *
     */
    @ApiOperation(value = "提现")
    @PostMapping
    @SysLog(value = "绑定收款帐号", request = false)
    @PreAuth("hasPermit('{}add')")
    public R<Boolean> doCashOut(@RequestBody @Validated CashOutDetailSaveDTO collectingAccountSaveDTO) {
        return cashOutDetailService.doCashOut(collectingAccountSaveDTO);
    }


    /**
     * 提现明细分页
     *
     */
    @ApiOperation(value = "提现明细分页查询")
    @PostMapping("/page")
    @SysLog(value = "提现明细分页查询", request = false)
    @PreAuth("hasPermit('{}page')")
    public R<IPage<CashOutDetailVO>> findCashOutDetailPage(@RequestBody PageParams<CashOutDetailPageDTO> pageParams) {
        return cashOutDetailService.findCashOutDetailPage(pageParams);
    }

    /**
     * 提现明细分页
     *
     */
    @ApiOperation(value = "提现审核分页")
    @PostMapping("/page/audit")
    @SysLog(value = "提现审核分页查询", request = false)
    @PreAuth("hasPermit('{}page')")
    public R<IPage<CashOutAuditDTO>> findAuditCashOutDetailPage(@RequestBody PageParams<CashOutAuditPageDTO> pageParams) {
        return cashOutDetailService.findAuditCashOutDetailPage(pageParams);
    }

    /**
     * 提现审核
     *
     */
    @ApiOperation(value = "提现审核")
    @PostMapping("/audit")
    @SysLog(value = "提现审核", request = false)
    @PreAuth("hasPermit('{}page')")
    public R<Boolean> auditCashOut(@RequestBody CashOutAuditDTO cashOutAuditDTO) {
        return cashOutDetailService.auditCashOut(cashOutAuditDTO);
    }

    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键", dataType = "long", paramType = "query"),})
    @ApiOperation(value = "查询提现审核", notes = "查询提现审核")
    @GetMapping("/audit/{id}")
    @SysLog("'查询提现审核:' + #id")
    @PreAuth("hasPermit('{}view')")
    public R<CashOutAuditDTO> getCashOutAudit(@PathVariable Long id) {
        return cashOutDetailService.getCashOutAudit(id);
    }

}
